/**
 * @param {number[]} temperatures
 * @return {number[]}
 */
export var dailyTemperatures = function (temperatures) {
  let ans = new Array(temperatures.length).fill(0)
  let stack = []
  for (let i = 0; i < temperatures.length; i++) {
    while (stack.length && temperatures[stack[stack.length - 1]] < temperatures[i]) {
      let j = stack.pop()
      ans[j] = i - j
    }
    stack.push(i)
  }
  return ans
}
